home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_214 / mandelvroom / src / cmd.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  12KB  |  412 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents: this file contains the IntuiMessage handler (also referred to
  25.  * as the command handler.)  This code implements a command-state state
  26.  * machine.
  27.  */
  28.  
  29. #include "mandp.h"
  30.  
  31. extern struct Picture *ZoomedPict;
  32.  
  33. BYTE State;
  34. BYTE Parse_rc;
  35.  
  36. ProcessCmd(Msg)
  37.   struct IntuiMessage *Msg;
  38. {
  39.   DecodeClass(Msg);         /* decode input by class */
  40.   PostProcessMsg(Msg);      /* set current pen, contour, or range */
  41.   DisplayMsg();             /* Display a message in the title bar */
  42.  
  43.   if (State == IDLESTATE) {
  44.     SetNormPointer();
  45.   }
  46. }
  47.  
  48. /*
  49.  * This function serves the following purposes:
  50.  *    1. Reacts to menu items and command gadgets (overriding whatever
  51.  *       the outstanding state is.)
  52.  *    2. Filters of messages that do not affect the state of
  53.  *       user interaction (NEWSIZE, REFRESHWINDOW, CLOSEWINDOW...)
  54.  *    3. It only allows MOUSEBUTTON messages to get past this
  55.  *       routine if they are desired.
  56.  */
  57.  
  58. DecodeClass(Msg)
  59.   struct IntuiMessage *Msg;
  60. {
  61.   register struct Window  *Window = Msg->IDCMPWindow;
  62.   struct Picture *Pict;
  63.  
  64.   switch( Msg->Class ) {
  65.  
  66.          /* These Classes can cause State to be set */
  67.  
  68.     case MENUPICK:
  69.          HandleMenuPick( Msg );
  70.          break;
  71.  
  72.     case GADGETDOWN:
  73.          HandleGadgetCmd(Msg);
  74.          break;
  75.  
  76.     case MOUSEBUTTONS:
  77.          /* filter unwanted SELECTDOWNS and SELECTUPS */
  78.          /* So that each of cmd routines below don't  */
  79.          /* have to ignore them                       */
  80.  
  81.          if (Msg->IDCMPWindow == ContWind) {
  82.  
  83.            SlideBarCmd(Msg);
  84.          } else {
  85.  
  86.            Pict = (struct Picture *) Window->UserData;
  87.  
  88.            if (Pict != NULL) {
  89.  
  90.              /* ignore Project buttons outside the picture area */
  91.  
  92.              if (Msg->Code == SELECTUP || Msg->Code == SELECTDOWN  &&
  93.                  MouseX >= Pict->LeftMarg &&
  94.                  MouseY >= Pict->TopMarg  &&
  95.                  MouseX <  Window->Width  - Pict->RightMarg &&
  96.                  MouseY <  Window->Height - Pict->BotMarg ) {
  97.  
  98.                DecodeState(Msg);
  99.              }
  100.            }
  101.          }
  102.          break;
  103.  
  104.          /* this message class cancels any command (i.e. clear state ) */
  105.  
  106.     case CLOSEWINDOW:
  107.          CloseWinds( Window );
  108.          State = IDLESTATE;
  109.          break;
  110.  
  111.          /* The response to these message classes depends on what we're
  112.           * doing.
  113.           */
  114.  
  115.     case MOUSEMOVE:
  116.          DecodeState(Msg);
  117.          break;
  118.  
  119.     case GADGETUP:
  120.          HandleGadgetCmd(Msg);
  121.       /* DecodeState(Msg); */
  122.          break;
  123.  
  124.          /* these message classes do not modify state */
  125.  
  126.     case ACTIVEWINDOW:
  127.          ActivatePict( Window );
  128.          break;
  129.  
  130.     case NEWSIZE:
  131.          if (Window != BackWind) {
  132.            BorderWindow( Window );
  133.  
  134.            if (Window->UserData) {
  135.              ScrollPictCmd(Msg);
  136.            }
  137.          }
  138.          break;
  139.  
  140.     default:
  141.          printf("Unexpected msg class %04x\n",Msg->Class);
  142.          break;
  143.   }
  144. }
  145.  
  146. DisplayMsg()
  147. {
  148.   char *c;
  149.   c = NULL;
  150.  
  151.   switch(State) {
  152.   case COPYRIGHTSTATE:  c = "Copyright 1987,1989 Kevin Clague";        break;
  153.   case IDLESTATE:       c = "MandelVroom V2.0 by Kevin Clague";        break;
  154.   case SETCONTSTATE:    c = "You can set color or height";             break;
  155.   case ORBITSTATE:      c = "Press left mouse button in Project";      break;
  156.   case SETJULIASTATE:   c = "Press left mouse button in Mand Project"; break;
  157.   case ZOOMINSTATE:     c = "Place the Zoom box in a Project";         break;
  158.   case COPYRGBSTATE:    c = "Select a color pen to copy RGBs";         break;
  159.   case SPREADRGBSTATE:  c = "Select a color pen to spread RGBs";       break;
  160.   case XCHGRGBSTATE:    c = "Select a color pen to exchange RGBs";     break;
  161.   case CYCLERANGESTATE: c = "Select a color pen to complete range";    break;
  162.   case SMOOTHCONTSTATE: c = "Select a contour pen to smooth heights";  break;
  163.   case CUTCONTSTATE:    c = "Select a contour pen to cut a pattern";   break;
  164.   case COPYCONTSTATE:   c = "Select a contour pen to copy a pattern";  break;
  165.   case PASTECONTSTATE:  c = "Select a contour pen to paste a pattern"; break;
  166.   case HELPSTATE:       c = "Select a menu or gadget for help";        break;
  167.   case SCROLLPICTSTATE: c = "Use the mouse to pan the current project";break;
  168.   case SETHEIGHTSTATE:  c = "Mouse changes contour's lower bound";     break;
  169.   case SLIDERGBSTATE:   c = "Move the mouse to change RGB values";     break;
  170.   case SLIDEBARSTATE:   c = "Move the mouse to scroll contours";       break;
  171.   case RESIZEZOOMSTATE: c = "Move the mouse to size the Zoom box";     break;
  172.   case ZOOMDRAGSTATE:   c = "Move the mouse to drag the Zoom box";     break;
  173.   case PROPRESIZESTATE: c = "Move the mouse to size the Zoom box";     break;
  174.   case SCROLLHELPSTATE: c = "Move the mouse to scroll help info.";     break;
  175.   case SLIDESPEEDSTATE: c = "Move the mouse to change speed";          break;
  176.   }
  177.  
  178.   /* only display the message if it is a new one */
  179.  
  180.   if (c && screen->Title != c) {
  181.     SetWindowTitles( CurWind, (char *) -1, c );
  182.   }
  183. }
  184.  
  185. DecodeState(Msg)
  186.   struct IntuiMessage *Msg;
  187. {
  188.   switch(State) {
  189.     case COPYRIGHTSTATE:
  190.     case IDLESTATE:        DecodeMsg(Msg);      break;
  191.     case COPYRGBSTATE:     CopyRGBCmd(Msg);     break;
  192.     case SPREADRGBSTATE:   SpreadRGBCmd(Msg);   break;
  193.     case XCHGRGBSTATE:     ExchangeRGBCmd(Msg); break;
  194.     case SLIDERGBSTATE:    SlideRGBCmd(Msg);    break;
  195.     case SETHEIGHTSTATE:   SetHeightCmd(Msg);   break;
  196.     case SETCONTSTATE:     SetContCmd(Msg);     break;
  197.     case SMOOTHCONTSTATE:  SmoothContCmd(Msg);  break;
  198.     case CUTCONTSTATE:     CutContCmd(Msg);     break;
  199.     case COPYCONTSTATE:    CopyContCmd(Msg);    break;
  200.     case PASTECONTSTATE:   PasteContCmd(Msg);   break;
  201.     case SLIDEBARSTATE:    SlideBarCmd(Msg);    break;
  202.     case ORBITSTATE:       OrbitCmd(Msg);       break;
  203.     case ZOOMINSTATE:      ZoomInCmd(Msg);      break;
  204.     case RESIZEZOOMSTATE:  ResizeZoomCmd(Msg);  break;
  205.     case QUERYHEIGHTSTATE: QueryHeightCmd(Msg); break;
  206.     case ZOOMDRAGSTATE:    ZoomDragCmd(Msg);    break;
  207.     case PROPRESIZESTATE:  PropResizeCmd(Msg);  break;
  208.     case SETJULIASTATE:    SetJuliaCmd(Msg);    break;
  209.     case SLIDESPEEDSTATE:  SlideSpeedCmd(Msg);  break;
  210.     case CYCLERANGESTATE:  CycleRangeCmd(Msg);  break;
  211.     case SCROLLHELPSTATE:  ScrollHelpCmd(Msg);  break;
  212.     case SCROLLPICTSTATE:  ScrollPictCmd(Msg);  break;
  213.   }
  214. }
  215.  
  216. /*
  217.  * Set Current pen or current contour.
  218.  */
  219.  
  220. PostProcessMsg(Msg)
  221.   struct IntuiMessage *Msg;
  222. {
  223.   register struct Window  *Window = Msg->IDCMPWindow;
  224.   struct Gadget *gadget;
  225.   int    id;
  226.  
  227.   if (Msg->Class == GADGETDOWN) {
  228.  
  229.     gadget = (struct Gadget *) Msg->IAddress;
  230.     id = gadget->GadgetID;
  231.     switch (WIND_TYPE(id)) {
  232.  
  233.       case PALTYPE:
  234.            if (GADG_TYPE(id) == PALPENS) {
  235.              SetCurPen(GADG_NUM(id));
  236.            }
  237.            break;
  238.  
  239.       case CONTYPE:
  240.            if ((GADG_TYPE(id) == CONTSELS || GADG_TYPE(id) == CONTPOTS) &&
  241.              id != CONTLAST) {
  242.  
  243.              SelContCmd(Msg);
  244.            }
  245.     }
  246.   }
  247. }
  248.  
  249. /*
  250.  * This is mostly for MOUSEBUTTON related commands (where the MOUSEBUTTONS
  251.  * are commands like drag, close or resize zoom box.)
  252.  */
  253.  
  254. DecodeMsg(Msg)
  255.   struct IntuiMessage *Msg;
  256. {
  257.   switch( Msg->Class ) {
  258.  
  259.     case MOUSEBUTTONS:
  260.          /* query height */
  261.          DecodePictMouseButtons( Msg );
  262.          break;
  263.   }
  264. }
  265.  
  266. HandleGadgetCmd(Msg)
  267.   struct IntuiMessage *Msg;
  268. {
  269.   struct Gadget *gadget;
  270.   int id, type, num;
  271.  
  272.   if (State == HELPSTATE) {
  273.     HelpGadgetCmd(Msg);
  274.     State = IDLESTATE;
  275.     return;
  276.   }
  277.  
  278.   gadget = (struct Gadget *) Msg->IAddress;
  279.  
  280.   id   = gadget->GadgetID;
  281.   type = GADG_TYPE(id);
  282.  
  283.   switch( WIND_TYPE(id)) {
  284.  
  285.     case PICTTYPE:
  286.          State = IDLESTATE;
  287.          switch (id) {
  288.            case PICTGEN:   GenerateCmd(Msg); break;
  289.            case PICTIN:    ZoomInCmd(Msg);   break;
  290.            case PICTOUT:   ZoomOutCmd(Msg);  break;
  291.            case PICTJULIA: SetJuliaCmd(Msg); break;
  292.          }
  293.          MakeCurProj((struct Picture *) Msg->IDCMPWindow->UserData);
  294.          break;
  295.  
  296.     case PALTYPE:
  297.          StopCycle();
  298.          switch (type) {
  299.            case PALPENS:          DecodeState(Msg);    break;
  300.            case PALPOTS:          SlideRGBCmd(Msg);    break;
  301.            case PALCNTLS:
  302.                 switch (id) {
  303.                   case PALCOPY:   CopyRGBCmd(Msg);     break;
  304.                   case PALRANGE:  SpreadRGBCmd(Msg);   break;
  305.                   case PALEXCG:   ExchangeRGBCmd(Msg); break;
  306.                 }
  307.                 break;
  308.          }
  309.          break;
  310.  
  311.     case CYCTYPE:
  312.          switch (type) {
  313.            case CYCRNUMS:         SelRangeCmd(Msg);   break;
  314.            case CYCCNTLS:
  315.                 switch (id) {
  316.                   case CYCSPEED:  SlideSpeedCmd(Msg); break;
  317.                   case CYCRANGE:  CycleRangeCmd(Msg); break;
  318.                   case CYCDIR:    ToggleDirCmd(Msg);  break;
  319.                   case CYCON:     CycleOnOffCmd(Msg); break;
  320.                 }
  321.                 break;
  322.  
  323.          }
  324.          break;
  325.  
  326.     case CONTYPE:
  327.          StopCycle();
  328.          switch (type) {
  329.            case CONTSELS:         DecodeState(Msg);   break;
  330.            case CONTPOTS:         SetHeightCmd(Msg);  break;
  331.            case CONTCNTLS:
  332.                 switch (id) {
  333.                   case CONTRECOL: PaintCmd(Msg);      break;
  334.                   case CONTSET:   SetContCmd(Msg);    break;
  335.                   case CONTSMTH:  SmoothContCmd(Msg); break;
  336.                   case CONTCUT:   CutContCmd(Msg);    break;
  337.                   case CONTCOPY:  CopyContCmd(Msg);   break;
  338.                   case CONTPASTE: PasteContCmd(Msg);  break;
  339.                   case CONTCEIL:  CeilingCmd(Msg);    break;
  340.                 }
  341.                 break;
  342.          }
  343.          break;
  344.  
  345.     case ORBTTYPE:
  346.          OrbitCmd(Msg);
  347.          break;
  348.  
  349.     case HELPTYPE:
  350.          switch (id) {
  351.  
  352.            case HELPUP:
  353.            case HELPDOWN:
  354.                 Page_File(id);
  355.                 break;
  356.  
  357.            case HELPSCROLL:
  358.                 ScrollHelpCmd(Msg);
  359.                 break;
  360.          }
  361.   }
  362. }
  363.  
  364. DecodePictMouseButtons( Msg )
  365.   struct IntuiMessage *Msg;
  366. {
  367.   register struct Node    *zNode;
  368.   register struct Picture *ZoomPict;
  369.   register struct Picture *Pict;
  370.            struct Picture *PictAddr();
  371.   int rc;
  372.  
  373.   Pict = (struct Picture *) Msg->IDCMPWindow->UserData;
  374.  
  375.   zNode = Pict->zList.lh_Head;
  376.  
  377.   rc = NOTHINGHIT;
  378.  
  379.   while ( rc == NOTHINGHIT && zNode->ln_Succ ) {
  380.  
  381.     ZoomPict = PictAddr( zNode );
  382.  
  383.     switch( rc = CheckPictZoomBox( ZoomPict ) ) {
  384.  
  385.       case ZOOMCLOSEHIT: /* User closed the zoom box */
  386.            ClearZoomBox( ZoomPict );
  387.            break;
  388.  
  389.       case ZOOMDRAGHIT:
  390.            ZoomedPict = ZoomPict;
  391.            ZoomDragCmd(Msg);
  392.            break;
  393.  
  394.       case ZOOMRESIZEHIT:
  395.            ZoomedPict = ZoomPict;
  396.            ResizeZoomCmd(Msg);
  397.            break;
  398.  
  399.       case PROPRESIZEHIT:
  400.            ZoomedPict = ZoomPict;
  401.            PropResizeCmd(Msg);
  402.            break;
  403.     }
  404.  
  405.     zNode = zNode->ln_Succ;
  406.   }
  407.  
  408.   if (rc == NOTHINGHIT) {
  409.     QueryHeightCmd(Msg);
  410.   }
  411. }
  412.